package com.example.alarm.mvvm.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.example.alarm.mvvm.bean.AlarmTypeBean
import com.example.alarm.mvvm.fragment.AlarmListFragment

/**
 * @author : lj
 * @date : 2021/1/6 11:03
 */
class AlarmPagerAdapter (fm: FragmentManager, titles: MutableList<AlarmTypeBean>): FragmentPagerAdapter(fm) {
    private var mtitles: MutableList<AlarmTypeBean>? = null
    var mFragments: ArrayList<AlarmListFragment> = ArrayList()

    init {
        this.mtitles = titles
        mtitles?.forEach {
            mFragments.add(AlarmListFragment.newInstance(it.code))
        }
    }

    override fun getItem(position: Int): Fragment {
        return mFragments!![position]
    }

    override fun getCount(): Int {
        return mFragments!!.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return mtitles?.let {
            it[position].name
        }
    }
}